package com.ryan.route.controller;


import com.ryan.route.entity.RouteDescription;
import com.ryan.route.service.RouteDescriptionService;
import com.ryan.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 路线详情 前端控制器
 * </p>
 *
 * @author ryan
 * @since 2020-07-27
 */
@RestController
@RequestMapping("/route/description")
public class RouteDescriptionController {

    @Autowired
    private RouteDescriptionService descriptionService;

    /**
     * 添加路线简介
     * @param description
     * @return
     */
    @PostMapping("/addDescription")
    public R addDescription(@RequestBody RouteDescription description){
        boolean save = descriptionService.save(description);
        return save?R.ok():R.error();
    }

    /**
     * 更新简介信息
     * @param description
     * @return
     */
    @PostMapping("/updateDescription")
    public R updateDescription(@RequestBody RouteDescription description){
        boolean update = descriptionService.updateById(description);
        return update?R.ok():R.error();
    }

    /**
     * 通过id获取路线简介
     * @param id
     * @return
     */
    @GetMapping("/getDescriptionById/{id}")
    public R getDescriptionById(@PathVariable String id){
        RouteDescription description = descriptionService.getById(id);
        return R.ok().data("description",description);
    }

}

